package com.allwees.core.common.mvc;

import com.allwees.core.common.mvc.converter.StringLongToDateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import javax.annotation.PostConstruct;

@Configuration
public class MvcConfig {
	@Autowired
	private RequestMappingHandlerAdapter handlerAdapter;

	/**
	 * 增加Long，String转日期的功能
	 */

	@PostConstruct
	public void initEditableAvlidation() {
		ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter.getWebBindingInitializer();
		if(initializer.getConversionService() != null) {
			GenericConversionService genericConversionService = (GenericConversionService) initializer.getConversionService();
			genericConversionService.addConverter(new StringLongToDateConverter());
		}
	}
}
